
#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include "Log.hpp"
#include <string>
#include <stdio.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include"InetAddr.hpp"
#include<functional>
#include"thread.hpp"
#include"Common.hpp"
#include"Socket.hpp"
#include"Protocol.hpp"
#include"Cal.hpp"
#include<iostream>

using namespace kzz;


// using namespace std;
int main(int argc, char **argv)
{
    ////在命令行传入服务器的IP和端口
    if (argc != 3)
    {
        kzz::LOG(LogLevel::ERROR) << "客户端参数传入错误";
        return 2;
    }
  
    uint16_t port=std::stoi(argv[2]);
    std::string ip=argv[1];
    std::shared_ptr<TcpSocket> socket=std::make_shared<TcpSocket>();
    socket->BuildTcpClientSocketMethod();
    socket->Connect(ip,port);
    kzz::Cal cal;
    while(true)
    {
    int x,y;
    char oper;
    std::cout << "Place Enter X:"<<std::endl;
    std::cin>>x;
     std::cout << "Place Enter Y:"<<std::endl;
    std::cin>>y;
     std::cout << "Place Enter Oper:"<<std::endl;
    std::cin>>oper;
    kzz::Request req(x,y,oper);
    std::string json_str=req.Serialize();
    kzz::Protocol pro([&cal](kzz::Request& req){return cal.Execute(req);});
    pro.EnCode(json_str);
    socket->Send(json_str);
    std::string rev;
    socket->Recv(rev);

    std::cout<<rev.c_str()<<std::endl;
    }
    



    //kzz::Protocol pro([&cal](kzz::){

  //  });


   return 0;
}